/******************************************************************
 * @version      : 1.0
 * @Author       : zhl
 * @Date         : 2023-05-16 14:08:01
 * @LastEditors  : zhl
 * @E-Mail       : zhll168@163.com
 * @Description  : 业务描述
 ******************************************************************/

#ifndef __FILE_DOWNLOAD_H__
#define __FILE_DOWNLOAD_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>

#include <string>
#include <iostream>


typedef struct _UPGRADE_PACKET_STRUCT{
    FILE *fp;
    size_t size;
}UPGRADE_PACKET_STRUCT;

class FileDownload
{
private:
    /* data */
    static FileDownload c_instance;
    CURL *c_curl;

public:
    FILE   *c_fp;
    size_t c_download_size;
    size_t c_total_size;
public:
    FileDownload(/* args */);
    ~FileDownload();

    CURLcode init(const char *target, const char *username, const char *password);
    void finish();
    CURLcode download(std::string strUrl);
    static int  progress(FileDownload *fdownload, double dltotal, double dlnow, double ultotal, double ulnow);
    static size_t write_to_file(void *contents, size_t size, size_t nmemb, FileDownload *fdownload);


    static FileDownload &getInstance();

};

#endif /* __FILE_DOWNLOAD_H__ */